#include<iostream>

using namespace std;

const int N = 300;
char l[N], r[N];
char root;
int n;

void dfs(char root)
{
	if(root == '*')
	    return;
	cout << root;
	dfs(l[root]);
	dfs(r[root]);
}
int main()
{
	cin >> n;
	cin >> root;
	cin >> l[root] >> r[root];
	for(int i = 2; i<= n; i++)
	{
		char t;
		cin >> t;
		cin>> l[t] >> r[t];
	}
	dfs(root); 
	return 0;
}
